var express = require('express');
var router = express.Router();
const goodsController = require('../controllers/cart_controller');
const  cart =require('../models/cart_bean')

//增加购物车
router.post('/addcart', function (req, res) {
    console.log(req.body.goodsid);
    console.log(req.body.userid,req.body.goodsid,req.body.data,req.body.qty);
    goodsController.addcart(new cart.carts(req.body.userid,req.body.goodsid,req.body.data,req.body.qty),(ret) =>res.json(ret)
    ,
    (err) => res.json(err)
    )
})

//获取购物车数据
router.post('/selectcart', function (req, res) {
    goodsController.getcart(new cart.select(req.body.userid,req.body.page,req.body.size),(ret) =>res.json(ret)
    ,
        (err) => res.json(err)
    )
})


//删除数据
router.delete('/deletecart', function (req, res) {
    console.log(req.body.userid,req.body.qty);
   goodsController.deletecart(new cart.deltete(req.body.userid,req.body.goodsid),(ret) =>res.json(ret)
    ,
       (err) => res.json(err)
   )
})


//修改数据
router.put('/updatacart', function (req, res) {
    goodsController.updatecart(new cart.update(req.body.userid,req.body.goodsid,req.body.qty),(ret) =>res.json(ret)
    ,
        (err) => res.json(err)
    )
})


module.exports =router